package com.ktmall.ktmalluijava.controller;

import com.ktmall.ktmalluijava.pojo.Cart;
import com.ktmall.ktmalluijava.service.CarService;
import com.ktmall.ktmalluijava.utils.Page;
import com.ktmall.ktmalluijava.utils.ResMsg;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/5/10 上午8:40
 */
@RestController
@RequestMapping("/cart/user/info")
public class CartController {

    @Resource
    private CarService carService;

    @GetMapping("/list")
    public String select(String username, String goodsName, Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null ? 1 : pageNo;
        pageSize = pageSize == null ? 5 : pageSize;
        Page<Cart> page = carService.getPage(username, goodsName, pageNo, pageSize);
        return ResMsg.success("购物车列表加载成功", page);
    }

    @PostMapping("/del")
    public String delete( @RequestBody Integer...id) {
        int row = carService.delete(id);
        if (row > 0) {
            return ResMsg.success("删除成功");
        } else {
            return ResMsg.error("删除失败");
        }
    }
}
